package logic

import (
	"context"
	"errors"
	"renting-demo/model/mysql"

	"renting-demo/user_srv/internal/svc"
	"renting-demo/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
	return &GetUserInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// Todo:获取用户信息
func (l *GetUserInfoLogic) GetUserInfo(in *user.GetUserInfoRequest) (*user.GetUserInfoResponse, error) {
	// todo: add your logic here and delete this line

	res := mysql.GetUserIdentity(in.UserID)
	if res.UserId == 0 {
		return nil, errors.New("查询失败")
	}
	return &user.GetUserInfoResponse{
		UserID:       int64(res.UserId),
		IdentityCard: res.IdentityCard,
		RealName:     res.RealName,
	}, nil
}
